new Vue({
    el: '#socket',
    data: {
        name: 'Welcome to',
        sendObj: {name:"All", value:'0'},
        myChat: {name: '', time: '', content: '',flag: 1},
        chatList: [
            {name: '小明', time: '2018-08-11 17:20:32', content: 'Hi, 大家好',flag: 0},
            {name: '小李', time: '2018-08-11 17:20:32', content: '小明, 你好',flag: 1},
        ],
        friendList: [
            {name: 'a', value: '1231231'},
            {name: 'b', value: '1231231'},
            {name: 'c', value: '1231231'},
            {name: 'd', value: '1231231'},
            {name: 'e', value: '1231231'},
        ]
    },
    methods:{
        sendTo(i){
            this.sendObj = this.friendList[i]
        },
        send(){
            const that = this;
            var temp ={};
            for(var key in that.myChat ){
                temp[key] = that.myChat[key]
            }
            that.myChat.time = new Date();

            this.chatList.push(temp);
            temp ={}
            this.socket.emit('send',that.myChat);
            that.myChat.content = '';
        }
    },
    mounted(){
        var socket = io('http://192.168.1.108:3009');
        const that = this
        this.socket = socket;
        function a(){
            socket.emit('send')
        }
        function b(){
            socket.emit('update')
        }
        socket.on('chat',function(data){
            document.getElementById('num').innerHTML = data.number;
            console.log('News', data)
        })
        socket.on('number',function(data){
            document.getElementById('num').innerHTML = data.number;
            console.log('News', data)
        })

        socket.on('line',function(data){
            // document.getElementById('status').innerHTML = data.status;
            console.log('News', data)
        });
        socket.on('news',function(data){
            console.log('News', data)
        });
        socket.on('message',function(data){
            console.log('获取的数据',data)
            that.chatList.push(data.data)
        })
    }
})